var express = require("express");
var router = express.Router();


var bodyParser = require("body-parser");
var urlencodedParser = bodyParser.urlencoded({ extended: false });

var user = require("../model/user");
var essay = require("../model/essay");

router.post("/add-comment", urlencodedParser, function(req, res) {
    var essayId = req.body.essayId;
    var content = req.body.content;
    var userId = req.session.passport.user;

    console.log(req.body);
    essay.findById(essayId, function(err, doc) {

        console.log({ commentUser: userId, commentContent: content });
        doc.comments.push({ commentUser: userId, commentContent: content });
        console.log(doc);
        doc.save();
        res.send({ code: 0, status: 0, message: "添加成功" });
    });
});

module.exports = router;